package com.sdjenkins.test;

import java.util.Collection;
import java.util.List;

import org.hibernate.Session;
import org.hibernate.Transaction;

import com.sdjenkins.sms.Collector;
import com.sdjenkins.sms.WASms;
import com.sdjenkins.sms.Sms;
import com.sdjenkins.sms.srv.Service;




public class Save {

	Session session = Service.getSession();	

	public static void main(String[] args) {
		Save save = new Save();
		save.go();
	}
	
	private void save(Sms sms) {
		
		Transaction tr = session.beginTransaction();
		session.save(sms);
		tr.commit();
		session.close();
				
	}
	private void go() {

		/*"sms_All Phones2.xml",
		"sms_All Phones3.xml",
		"sms_All Phones4.xml",
		"sms_All Phones5.xml",
		"sms_All Phones6.xml",
		"sms_All Phones7.xml"*/		
		
		CollectWa wac = new CollectWa();
		saveAll(wac.addFromFile("tmptime5.xml"));
		
	}
	private void saveAll(Collection<Collector> all) {
		
		Transaction tr = session.beginTransaction();
		for (Collector sms : all) {	
			if( sms.getAddress() == null) {
				System.out.println("no addr");
			}
			session.save(sms);
		}
		tr.commit();
		session.close();		
		
	}
	
}
